<?php
class ControllerPhoto { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newPhoto();
                break;
            
            case "list":
                $this->listPhoto();
                break;
            
            case "save":
                $this->savePhoto();
                break;

            case "edit":
                $this->editPhoto();
                break;
            
            case "update":
                $this->updatePhoto();
                break;
            
            case "del":
                $this->deletePhoto();
                break;
            
            case "combo":
                return $this->comboPhoto();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newPhoto(){
        include_once "vista/vista.photo.php";
        form_photo();
    }    
    

    function savePhoto(){
        include_once "modelo/modelo.photo.php";
        
        $p = new photo();
        $p->set_ph_id($_REQUEST["ph_id"]); 
        $p->set_ph_u_id($_REQUEST["ph_u_id"]); 
        $p->set_ph_desc($_REQUEST["ph_desc"]); 
        $p->set_ph_img_route($_REQUEST["ph_img_route"]); 
        $p->set_ph_img_mini_route($_REQUEST["ph_img_mini_route"]); 
        $p->set_ph_img_name($_REQUEST["ph_img_name"]); 
        $p->set_ph_date($_REQUEST["ph_date"]); 
        $p->set_ph_location($_REQUEST["ph_location"]); 
        $p->set_ph_status($_REQUEST["ph_status"]); 

        
        if($p->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listPhoto($msj);
        
    }    
    
    function editPhoto(){
        include_once 'modelo/modelo.photo.php';
        include_once 'vista/vista.photo.php';
        
        $p = new photo();
        $p->setph_id($_REQUEST["ph_id"]); 
        
        $p->getData();
        
        form_photo($p);
        
    }    
    
    function deletePhoto(){
        include_once 'modelo/modelo.photo.php';
        
        $p = new photo();
        $p->setph_id($_REQUEST["ph_id"]); 
        
        if($p->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listPhoto($msj);
    }

    
    function updatePhoto(){
        include_once 'modelo/modelo.photo.php';
        
        $p = new photo();
        $p->set_ph_id($_REQUEST["ph_id"]); 
        $p->set_ph_u_id($_REQUEST["ph_u_id"]); 
        $p->set_ph_desc($_REQUEST["ph_desc"]); 
        $p->set_ph_img_route($_REQUEST["ph_img_route"]); 
        $p->set_ph_img_mini_route($_REQUEST["ph_img_mini_route"]); 
        $p->set_ph_img_name($_REQUEST["ph_img_name"]); 
        $p->set_ph_date($_REQUEST["ph_date"]); 
        $p->set_ph_location($_REQUEST["ph_location"]); 
        $p->set_ph_status($_REQUEST["ph_status"]); 

        if($p->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listPhoto($msj);
    }

    
    function listPhoto($msj=false){
        include_once 'modelo/modelo.photo.php';
        include_once 'vista/vista.photo.php';
        
        $p = new photo();

        $p->setph_id($_REQUEST["ph_id"]); 
        $p->getData();
        
        $dataTotal = $p->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $p->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_photo($data, $msj, $dataTotal);

    }

}